/*
 * @Author: 1086 cchcc@qq.com
 * @Date: 2024-04-23 00:36:55
 * @LastEditors: 1086 cchcc@qq.com
 * @LastEditTime: 2024-05-23 21:47:25
 * @FilePath: \erp\ui\admin\src\store\user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { HTTPmenu, permission } from "../api/module/user";
/** 用户个人缓存数据 */
export const useUserStore = defineStore({
  id: 'user',
  state: () => {
    return {
      token: '',//用户登录会话token
      userInfo: {},//用户帐号信息
      permissions: [],
      menus: [],//导航菜单
    }
  },
  actions: {
    async loadMenus(){
      // 请求导航菜单
      const { db, code } = await HTTPmenu();
      if (code == 200) {
        this.menus = db.txt_json;
      }
    },
    async loadPermissions(){
      // const { data, code } = await permission();
      // if(code == 200) {
      //   this.permissions = data;
      // }
    }
  },
  persist: {
    storage: localStorage,
    paths: ['token', 'userInfo', 'permissions', 'menus' ],
  }
})